package leetcode.median;

import java.util.*;

/**
 * ClassName: $49_GroupAnagrams
 * Description:
 * date: 2022-02-18 22:31
 *
 * @author liyifan
 */
public class $49_GroupAnagrams {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, ArrayList<String>> map = new HashMap<>();
        for (int i = 0;i < strs.length;i++) {
            char[] chars = strs[i].toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            ArrayList<String> list = map.getOrDefault(key, new ArrayList<>());
            list.add(strs[i]);
            map.put(key, list);
        }
        return new ArrayList<>(map.values());
    }
}
